<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>添加客户资源</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../static/layui/css/layui.css" media="all">
  <script src="../../static/js/jquery-3.6.0.min.js"></script>
  <script>
      var data = null;
      $.ajax({
          url:"/customer/queryCustomerList",
          method:"get",
          success:function (res){   //res为后端拿到的数据
              data = res.data;
              console.log(data);
              for(var i = 0; i<data.length;i++){
                  console.log(data[i]);
                  //jq动态添加选项
                  // console.log("<option value="+data[i].customer_code+">"+data[i].customer_code+"</option>");
                  $("#choose").after("<option value="+data[i].customer_code+">"+data[i].customer_code+"</option>");
              }
              var stringData = JSON.stringify(data);
              // console.log(stringData);
              localStorage.setItem("stringData",stringData);
          }
      })
  </script>
</head>
<body>

<form id="myform" class="layui-form" lay-filter="layuiadmin-form-admin" id="layuiadmin-form-admin" style="padding: 20px 30px 0 0;">
  <!--id在页面中隐藏了，前端传递给后端也传递了id值  -->
  <input type="hidden" name="id">
  <input type="hidden" name="ask_time" id="ask_time">
  <!--客户编码 客户姓名-->
  <div class="layui-form-item">
    <label class="layui-form-label"><b>客户编码：</b></label>
    <div class="layui-input-inline">
      <select id="customer_code" name="customer_code" lay-filter="customer_code" lay-search>
        <option value="" selected id="choose">-请选择-</option>
      </select>
    </div>
    <label class="layui-form-label required"><b>客户姓名：</b></label>
    <div class="layui-input-inline">
      <input type="text" name="customer_name" disabled autocomplete="off" class="layui-input">
    </div>
  </div>
  <!--性别 客户类型-->
  <div class="layui-form-item" pane="">
    <label class="layui-form-label required"><b>性别：</b></label>
    <div class="layui-input-inline">
      <input type="text" name="sex" disabled autocomplete="off" class="layui-input">
    </div>
    <label class="layui-form-label required"><b>客户类型：</b></label>
    <div class="layui-input-inline">
      <div class="layui-input-inline">
        <input type="text" name="type" disabled autocomplete="off" class="layui-input">
      </div>
    </div>
  </div>
  <!--客户状态 消费次数-->
  <div class="layui-form-item" pane="">
    <label class="layui-form-label required"><b>客户状态：</b></label>
    <div class="layui-input-inline">
      <input type="text" name="status" disabled autocomplete="off" class="layui-input">
    </div>
    <label class="layui-form-label required"><b>消费次数：</b></label>
    <div class="layui-input-inline">
      <div class="layui-input-inline">
        <input type="text" name="consume_times" disabled autocomplete="off" class="layui-input">
      </div>
    </div>
  </div>
  <script>

  </script>
  <hr>
  <!--质量满意度 服务满意度-->
  <div class="layui-form-item">
    <label class="layui-form-label required"><b>质量满意度：</b></label>
    <div class="layui-input-inline">
      <input type="text" name="quality_satisfaction" lay-verify="required" autocomplete="off" class="layui-input">
    </div>
    <label class="layui-form-label required"><b>服务满意度：</b></label>
    <div class="layui-input-inline">
      <input type="text" name="service_satisfaction" lay-verify="required" autocomplete="off" class="layui-input">
    </div>
  </div>
  <!--性价比满意度 总体满意度-->
  <div class="layui-form-item">
    <label class="layui-form-label required"><b>性价比满意度：</b></label>
    <div class="layui-input-inline">
      <input type="text" name="cost_satisfaction" lay-verify="required" autocomplete="off" class="layui-input">
    </div>
    <label class="layui-form-label required"><b>总体满意度</b>：</label>
    <div class="layui-input-inline">
      <input type="text" name="total_satisfaction" lay-verify="required" autocomplete="off" class="layui-input">
    </div>
  </div>
  <!--客户反馈-->
  <div class="layui-form-item">
    <label class="layui-form-label required"><b>客户反馈：</b></label>
    <div class="layui-input-inline">
      <textarea name="customer_feedback" lay-verify="required" autocomplete="off" class="layui-textarea"></textarea>
    </div>
  </div>
</form>
<script src="../../static/layui/layui.js"></script>
<script src="../../static/js/jquery-3.6.0.min.js"></script>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;
        //执行一个laydate实例
        laydate.render({
            elem: '#birth', //指定元素
            type: 'date' //含年月日，不含时分秒
        });
        laydate.render({
            elem: '#entry_time', //指定元素
            type: 'datetime' //既含年月日，也含时分秒
        });
    });
</script>


<script>
    layui.use('form', function () {
        var form = layui.form;
        form.on('select(customer_code)', function (data) {
            var stringData = localStorage.getItem("stringData");
            var d = JSON.parse(stringData);
            console.log(d);
            console.log(data.value);
            for (var i = 0; i < d.length; i++) {
                // console.log(d[i]);
                $.each(d[i],function (index,item){
                    // console.log(item)
                    if (data.value == item) {
                        $("input[name=id]").attr("value", d[i].id);
                        $("input[name=customer_name]").attr("value", d[i].customer_name);
                        if(d[i].sex==1){
                            $("input[name=sex]").attr("value", "男");
                        }else if(d[i].sex==2){
                            $("input[name=sex]").attr("value", "女");
                        }
                        $("input[name=type]").attr("value", d[i].type);
                        if(d[i].del_status==1){
                            $("input[name=status]").attr("value", "正常");
                        }else if(d[i].del_status==2){
                            $("input[name=status]").attr("value", "冻结");
                        }
                        $("input[name=consume_times]").attr("value", d[i].consume_times);
                    } else {
                    }
                    // console.log(customer_name);
                })
            }
        })
    })

    var date = new Date();
    var year = date.getFullYear();
    var month = ('0' + (date.getMonth() + 1)).slice(-2);
    var day = ('0' + date.getDate()).slice(-2);
    var time = year + "-" + month + "-" + day;
    // console.log(time);
    // document.getElementById("#customer_code").outerHTML = '<input type="text" name="customer_code" value='+time+'id="customer_code" disabled lay-verify="required" autoComplete="off" className="layui-input">';
    $("#ask_time").val(time);
</script>

</body>
</html>